import axios from "axios";
const situation = {
  state() {
    return {
      //支付金额
      payMoney: "",
      // 支付笔数
      troke: "",
      // 支付客单价
      price: "",
      //会员总数
      sumMember: "",
      //新增会员
      addMember: "",
      // 支付会员
      payMember: "",
      // 存储值会员数
      valueMember: "",
      setMemberList: [],
      //支付金额数组
      payMoneyList: [],
      //troke数组
      trokeList: [],
      //累计人数
      peopleList: [],
      //铂金
      platinumList: [],
      //黄金
      goldList: [],
      //钛金
      titaniumList: [],
      //超级
      superList: [],
    };
  },
  getters: {},
  mutations: {
    initMeberList(state, list) {
      state.setMemberList = list;
    },
    setPayMoney(state, money) {
      state.payMoney = money;
    },
    setTroke(state, troke) {
      state.troke = troke;
    },
    setPayMerber(state, payMember) {
      state.payMember = payMember;
    },
    setPrice(state, price) {
      state.price = price;
    },
    setSumMember(state, sum) {
      state.sumMember = sum;
    },
    setAddMember(state, item) {
      state.addMember = item;
    },
    setValueMember(state, item) {
      state.valueMember = item;
    },
    setPayMoneyList(state, item) {
      return state.payMoneyList.push(item);
    },
    setTrokeList(state, item) {
      return state.trokeList.push(item);
    },
    setPeopleList(state, list) {
      return (state.peopleList = list);
    },
    setPlatinumList(state, item) {
      return (state.platinumList = item);
    },
    setGoldList(state, item) {
      return (state.goldList = item);
    },
    setTitaniumList(state, item) {
      return (state.titaniumList = item);
    },
    setSuperList(state, item) {
      return (state.superList = item);
    },
  },
  actions: {
    async getPayMoney(context) {
      const { data: res } = await axios.get("/vip/orders/findTotalMoney", {
        params: { startTime: "2021-07-01", endTime: "2021-07-31" },
      });
      if (res.data.length == 0) {
        return context.commit("setPayMoney", 0);
      }
      // console.log(res.data);
      for (let item of res.data) {
        context.commit("setPayMoneyList", item.total);
      }
      context.commit("setPayMoney", res.data[res.data.length - 1].total);
    },
    //会员四模块
    async getMerber(context) {
      const { data: res } = await axios.post("/vip/user/analyse", {
        startTime: "2021-07-01",
        endTime: "2021-07-31",
      });
      // console.log(res.data);
      context.commit("setSumMember", res.data[0]);
      context.commit("setAddMember", res.data[1]);
      context.commit("setValueMember", res.data[3]);
    },
    //支付会员数
    async getPayMerber(context) {
      const { data: res } = await axios.get(
        "/vip/orders/findPaidUsersByWhere",
        {
          params: {
            startTime: "2021-07-01",
            endTime: "2021-07-31",
          },
        }
      );
      // console.log(res.data[res.data.length - 1]);
      if (res.data.length == 0) {
        return context.commit("setPayMerber", 0);
      }
      context.commit("setPayMerber", res.data[res.data.length - 1].userTotal);
    },
    //支付笔数
    async getTroke(context) {
      const { data: res } = await axios.get(
        "/vip/orders/findPaidNumberByWhere",
        {
          params: {
            startTime: "2021-07-01",
            endTime: "2021-07-31",
          },
        }
      );
      if (res.data.length == 0) {
        return context.commit("setTroke", 0);
      }
      // console.log(res.data);
      for (let item of res.data) {
        // console.log(item.orderTotal);
        context.commit("setTrokeList", item.orderTotal);
      }

      // console.log(res.data[res.data.length - 1].orderTotal);
      context.commit("setTroke", res.data[res.data.length - 1].orderTotal);
    },
    //支付客数
    async getPrice(context) {
      const { data: res } = await axios.get("/vip/orders/findUserAve", {
        params: {
          startTime: "2021-07-01",
          endTime: "2021-07-31",
        },
      });
      if (res.data.length == 0) {
        return context.commit("setPrice", 0);
      }
      // console.log(res.data[res.data.length - 1]);
      context.commit("setPrice", res.data[res.data.length - 1].ave);
    },
    //会员明细
    async getMeberList(context) {
      const { data: res } = await axios.get("/vip/DataDetails/find");
      // console.log(res);
      context.commit("initMeberList", res);
    },

    //累计会员数
    async getMerberNum(context) {
      const { data: res } = await axios.post("/vip/user/userMap", {
        startTime: "2021-07-01",
        endTime: "2021-07-31",
      });
      // console.log(res.data);
      context.commit("setPeopleList", res.data);
    },
    //占比
    async getProportion(context) {
      const { data: res } = await axios.post("/vip/user/userLevelMap", {
        startTime: "2021-07-01",
        endTime: "2021-07-31",
      });
      // console.log(res.data[0]);
      context.commit("setPlatinumList", res.data[0]);
      context.commit("setGoldList", res.data[1]);
      context.commit("setTitaniumList", res.data[2]);
      context.commit("setSuperList", res.data[3]);
    },
  },
  modules: {},
};

export default situation;
